#!/bin/bash
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $DIR/environment

DEPLOY='docker-compose run -w /polyaxon/deploy --rm --name=polyaxon_deploy web'

$DIR/check
if [ $? -eq 0 ]; then
    if [ "$1" = "setup" ]; then
        echo "Installing npm dependencies..."
        $DEPLOY npm install
    elif [ "$1" = "build" ]; then
        echo "Compiling ts to js..."
        $DEPLOY npm run build
    elif [ "$1" = "npm" ]; then
        $DEPLOY $*
    elif [ "$1" = "run" ]; then
        docker-compose run -w /polyaxon/deploy --publish 8001:8001 --rm --name=polyaxon_deploy web npm run dev
    fi
fi
